package com.gooluke.auth.exception;

import com.gooluke.common.domain.ErrorStatus;

/**
 * @author gooluke
 * description
 * datetime 2025-03-28 16:06
 */
public abstract class BaseException extends RuntimeException {

    protected int code = 500;
    protected String message = "系统繁忙，请稍后再试~";

    public BaseException() {
        super();
    }

    // 通过 ErrorStatus 构造异常
    public BaseException(ErrorStatus errorStatus) {
        super(errorStatus.getMessage());
        this.code = errorStatus.getCode();
        this.message = errorStatus.getMessage();
    }

    // 允许动态指定 code 和 message
    public BaseException(int code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    // 支持传递原始异常（cause）
    public BaseException(int code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
    }

    // 可重写此方法以禁用堆栈跟踪（提升性能）
    @Override
    public synchronized Throwable fillInStackTrace() {
        return this;
    }

}
